****APPENDIX TABLE C5****

cd "$main_dir/output/tables/appendix_c"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Generate relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1 yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1 yob_ln_gdppc)

merge m:1 ccode using "$data_dir/raw/democ_autoc_switch_media.dta", keepusing(low_media_freedom med_media_freedom high_media_freedom)
drop if _merge==2
drop _merge

merge m:1 ccode using "$data_dir/raw/average_gini_coefficients.dta", keepusing(equal)
drop if _merge==2
drop _merge

fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.

//--------------------------------------------------------
//Create Table C5
//--------------------------------------------------------

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & equal==0, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1 & equal==0, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c5.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE x Survey FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
													      Sample, Unequal) keep(zwgrowth_rate_1) 

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & equal==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1 & equal==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c5.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
													     Sample, Equal) keep(zwgrowth_rate_1) 

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & low_media_freedom==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1 & low_media_freedom==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c5.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
													     Sample, Unfree Media) keep(zwgrowth_rate_1) 

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & med_media_freedom==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1 & med_media_freedom==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c5.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
													     Sample, Semi-Free Media) keep(zwgrowth_rate_1) 
														 
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & high_media_freedom==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1 & high_media_freedom==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c5.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
													     Sample, Free Media) keep(zwgrowth_rate_1) 

